//
//  RegulationViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2017/10/26.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "RegulationViewController.h"
#import "DOPDropDownMenu.h"
#import "FGModel.h"
#import "RegulationCell.h"
#import "HHBaseLoadToken.h"

#define RegulationCellIndentifier @"RegulationCellIndentifier"

@interface RegulationViewController ()<UITableViewDelegate,UITableViewDataSource,DOPDropDownMenuDataSource,DOPDropDownMenuDelegate,TermCellDelegate>{
    int j;
    CGFloat cellTitH;
}

@property (weak,   nonatomic) DOPDropDownMenu *menu;
@property (nonatomic, strong) NSMutableArray *arrMfG;// 总数据数组
@property (nonatomic ,strong) NSMutableArray *FGFLArrM;// 法规分类数组
@property (nonatomic ,strong) NSMutableArray *FGFLIDArrM;// 法规分类id数组
@property (nonatomic ,strong) NSMutableArray *FGSZArrM;// 税种数组
@property (nonatomic ,strong) NSMutableArray *FGSZIDArrM;// 税种id数组
@property (nonatomic, strong) NSArray *RQArrM; //(下拉菜单)日期

@property (nonatomic ,strong) NSString *cid;// 参数（FGFLID）
@property (nonatomic ,strong) NSString *szid;// 参数（FGSZID）
@property (nonatomic ,strong) NSString *rq;// 参数（日期）

@end

@implementation RegulationViewController

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // 离开页面时收起menu.leftTableView 和 蒙尘层
    [_menu animateTableView:_menu.leftTableView show:NO complete:^{

    }];

    [_menu animateBackGroundView:_menu.mengcengView show:NO complete:^{

    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    j = 1;
    _cid = @"";
    _szid = @"";
    _rq = @"0";
    _FGFLArrM = [NSMutableArray array];
    _FGFLIDArrM = [NSMutableArray array];
    _FGSZArrM = [NSMutableArray array];
    _FGSZIDArrM = [NSMutableArray array];
    _arrMfG = [NSMutableArray array];
    _RQArrM = [NSArray array];


    NSArray *arrReturn = [WShareUtil readModelDataFromFile:@"RegulationList"];
    self.arrMfG = [NSMutableArray array];

    if (arrReturn != nil && arrReturn.count > 0) {
        for (NSDictionary *dic in arrReturn) {
            FGModel *fGmodel = [FGModel mj_objectWithKeyValues:dic];
            [self.arrMfG addObject:fGmodel];
        }
    }

    // 1.注册控件
    UINib *cellNib = [UINib nibWithNibName:@"RegulationCell" bundle:nil];
    [self.myTableView registerNib:cellNib forCellReuseIdentifier:RegulationCellIndentifier];

    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    self.prototypeCell  = [self.myTableView dequeueReusableCellWithIdentifier:RegulationCellIndentifier];

//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyRequestListData) name:NOTIFYFG object:nil];
//
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noWifiRefershingEnd) name:NOREFRESH object:nil];

//    [self notifyRequestListData];
    [self DOP];
}

- (void)noWifiRefershingEnd {
    [self.myTableView.header endRefreshing];
    [self.myTableView.footer endRefreshing];
    [WShareUtil sharedData].isShowWait = YES;

}

- (void)notifyRequestListData{ // 在这下载 列表数据 和 法规分类数据 和 法规税种

//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noWifiRefershingEnd) name:REFRESHINGEND object:nil];

    [self.FGFLArrM removeAllObjects];
    [self.FGFLIDArrM removeAllObjects];
    [self.FGSZArrM removeAllObjects];
    [self.FGSZIDArrM removeAllObjects]; // 清空数组，避免多次添加

    [self loadQueryFgFlList];// 法规分类
    [self loadqueryFgSzList];// 法规税种

    self.myTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

        [self requestListDataStrNum:@"1" isRefresh:YES];
        j = 1;
    }];

//    if (kIsHaveNetwork) //有网
//    {
        [_myTableView.header beginRefreshing];
//    } //else无网

    self.myTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{

        NSString *num = [NSString stringWithFormat:@"%d",++j];
        [self requestListDataStrNum:num isRefresh:NO];
    }];
}

#pragma mark - 下载法规分类数据
- (void)loadQueryFgFlList {

    if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strToken]) {

        HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];
        [loadToken loadToken];

        loadToken.tokenBlock = ^(NSString *strToken) {
            if (![WShareUtil strNilOrEmpty:strToken]) {
                [self loadQueryFgFlList];
            }else {
                WLog(@"没有token");
            }
        };
        WLog(@"%@",[WShareUtil sharedData].strToken);

    }else {
        NSString *uuid= @"e1e1e1";
        NSDictionary *parametersDict = @{@"jqbh":uuid,@"token":[WShareUtil sharedData].strToken};
        // 字典转JSON字符串
        NSString *jsonData = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];

        // 加密JSON字符串
        WLog(@"加密JSON字符串的结果%@",[CommonFunc encryptWithText:jsonData]);//加密方法
        WLog(@"解密乱码后的结果%@",[CommonFunc decryptWithText:@"sZjh+Dfxf1kcn5u4bgq"]);//解密方法

        // 加密后字典参数
        NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:jsonData]};

        [WHttpTool POST:[WShareUtil getServerURL:QUERYFGFLLIST] parameters:paramsDic success:^(id responseObject) {
            NSString *messageStr = [responseObject objectForKey:@"message"];
            NSString *successStr= [responseObject objectForKey:@"success"];
            // 解密请求回的数据（字典）
            [CommonFunc decryptWithText:messageStr];
            NSString *returnStr = [CommonFunc decryptWithText:messageStr];

            int code = [responseObject[@"success"] intValue];
            if (code == 1) { // 成功返回数组

                // json字符串转数组
                NSArray *returnArr = [WHttpTool arrayWithJsonString:returnStr];
                WLog(@"转化的(数组格式的)解密数据%@",returnArr);

                for (int i = 0; i < returnArr.count; i++) {
                    [_FGFLArrM addObject:returnArr[i][@"name"]];
                }
                WLog(@"法规分类数组-%@",_FGFLArrM);
                for (int h = 0; h < returnArr.count; h++) {
                    [_FGFLIDArrM addObject:returnArr[h][@"id"]];
                }
                WLog(@"法规分类id数组-%@",_FGFLIDArrM);

            }else if (code == 0) { // 失败返回字典

                // json字符串转字典
                NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

                if ([returnDic[@"resultCode"] isEqualToString:@"EC0001"] || [returnDic[@"resultCode"] isEqualToString:@"EC0002"] ) {
                    HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：token过期后，获取一次就关掉）
                    [loadToken loadToken];
                    loadToken.tokenBlock = ^(NSString *strToken) {
                        if (![WShareUtil strNilOrEmpty:strToken]) {
                            [self loadQueryFgFlList];
                        }else {

                            [WShareUtil showAlert:@"温馨提示" message:@"没有token"];

                            return ;

                            WLog(@"没有token");
                        }
                    };

                    WLog(@"%@====",[WShareUtil sharedData].strToken);
                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0005"]){

                    [WShareUtil showAlert:@"温馨提示" message:@"您的服务已经到期"];
                    return ;

                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0006"]){

                    [WShareUtil showAlert:@"温馨提示" message:@"您被禁止登录"];
                    return ;

                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0008"]){

                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的账号可能在其他设备登录,是否要重新登录？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新登录", nil];
                    [alertView show];
                    
                    [WShareUtil sharedData].dicSession = nil;
                    return ;
                    WLog(@"没有用户");
                    
                }
            }

        } failure:^(NSError *error) {
            WLog(@"请求失败");
        } showProgress:YES];
    }
}

#pragma mark - 下载法规税种数据
- (void)loadqueryFgSzList {

    if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strToken]) {

        HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];
        [loadToken loadToken];

        loadToken.tokenBlock = ^(NSString *strToken) {
            if (![WShareUtil strNilOrEmpty:strToken]) {
                [self loadqueryFgSzList];
            }else {
                WLog(@"没有token");
            }
        };
        WLog(@"%@",[WShareUtil sharedData].strToken);

    }else {
        NSString *uuid= @"e1e1e1";
        NSDictionary *parametersDict = @{@"jqbh":uuid,@"token":[WShareUtil sharedData].strToken};
        // 字典转JSON字符串
        NSString *jsonData = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];

        // 加密JSON字符串
        WLog(@"加密JSON字符串的结果%@",[CommonFunc encryptWithText:jsonData]);//加密方法
        WLog(@"解密乱码后的结果%@",[CommonFunc decryptWithText:@"sZjh+Dfxf1kcn5u4bgq"]);//解密方法

        // 加密后字典参数
        NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:jsonData]};

        [WHttpTool POST:[WShareUtil getServerURL:QUERYFGSZLIST] parameters:paramsDic success:^(id responseObject) {
            NSString *messageStr = [responseObject objectForKey:@"message"];
            NSString *successStr= [responseObject objectForKey:@"success"];
            // 解密请求回的数据（字典）
            [CommonFunc decryptWithText:messageStr];
            NSString *returnStr = [CommonFunc decryptWithText:messageStr];

            int code = [responseObject[@"success"] intValue];
            if (code == 1) { // 成功返回数组

                // json字符串转数组
                NSArray *returnArr = [WHttpTool arrayWithJsonString:returnStr];
                WLog(@"转化的(数组格式的)解密数据%@",returnArr);

                for (int i = 0; i < returnArr.count; i++) {
                    [_FGSZArrM addObject:returnArr[i][@"name"]];
                }
                WLog(@"法规税种数组-%@",_FGSZArrM);
                for (int h = 0; h < returnArr.count; h++) {
                    [_FGSZIDArrM addObject:returnArr[h][@"id"]];
                }
                WLog(@"法规税种id数组-%@",_FGSZIDArrM);

            }else if (code == 0) { // 失败返回字典

                // json字符串转字典
                NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

                if ([returnDic[@"resultCode"] isEqualToString:@"EC0001"] || [returnDic[@"resultCode"] isEqualToString:@"EC0002"] ) {
                    HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：token过期后，获取一次就关掉）
                    [loadToken loadToken];
                    loadToken.tokenBlock = ^(NSString *strToken) {
                        if (![WShareUtil strNilOrEmpty:strToken]) {

                            [self loadqueryFgSzList];

                        }else {

                            [WShareUtil showAlert:@"温馨提示" message:@"没有token"];

                            return ;

                            WLog(@"没有token");
                        }
                    };

                    WLog(@"%@====",[WShareUtil sharedData].strToken);
                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0005"]){

                    [WShareUtil showAlert:@"温馨提示" message:@"您的服务已经到期"];
                    return ;

                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0006"]){

                    [WShareUtil showAlert:@"温馨提示" message:@"您被禁止登录"];
                    return ;

                }else if([returnDic[@"resultCode"] isEqualToString:@"EC0008"]){

                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的账号可能在其他设备登录,是否要重新登录？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新登录", nil];
                    [alertView show];
                    
                    [WShareUtil sharedData].dicSession = nil;
                    return ;
                    WLog(@"没有用户");
                    
                }
            }

        } failure:^(NSError *error) {
            WLog(@"请求失败");
        } showProgress:YES];
    }
}

#pragma mark - 下载法规总列表数据
- (void)requestListDataStrNum:(NSString *)pageNum isRefresh:(BOOL)isRefresh{

    [WShareUtil sharedData].isShowWait = NO;

    if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strToken]) {
        HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：token过期后，获取一次就关掉）
        [loadToken loadToken];
        loadToken.tokenBlock = ^(NSString *strToken) {
            if (![WShareUtil strNilOrEmpty:strToken]) {
                [self requestListDataStrNum:pageNum isRefresh:isRefresh];
            }else {
                WLog(@"没有token");
            }
        };
        WLog(@"%@",[WShareUtil sharedData].strToken);
    }else {
        
        NSDictionary *parametersDict = @{@"pageNum":pageNum,@"pageSize":@"10",@"cid":_cid,@"szid":_szid,@"rq":_rq};
        // 字典转JSON字符串
        NSString *jsonData = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];

        // 加密JSON字符串
        WLog(@"加密JSON字符串的结果%@",[CommonFunc encryptWithText:jsonData]);//加密方法
        WLog(@"解密乱码后的结果%@",[CommonFunc decryptWithText:@"sZjh+Dfxf1kcn5u4bgq4g75bHbBQ6DlL2oF3ELtxXb8dkwb1w5GRyfm7huCriDvlsdsFDoOWLqzX7tt+NpCuiEApxy+2QONMEZpGLBejk+1ZPreDtd3O7Q=="]);//解密方法

        // 加密后字典参数
        NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:jsonData]};

        NSString *url = @"http://mobile.csfw360.com:18082/csfw_jiekou/hangxin/fgList";

        [WHttpTool POST:url parameters:paramsDic success:^(id responseObject) {
            NSString *messageStr = [responseObject objectForKey:@"message"];
            NSString *successStr= [responseObject objectForKey:@"success"];
            // 解密请求回的数据（字典）
            [CommonFunc decryptWithText:messageStr];
            NSString *returnStr = [CommonFunc decryptWithText:messageStr];
            // json字符串转字典
            NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

            if ([returnDic[@"resultCode"] isEqualToString:@"EC0001"] || [returnDic[@"resultCode"] isEqualToString:@"EC0002"] ) {
                HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：token过期后，获取一次就关掉）
                [loadToken loadToken];
                loadToken.tokenBlock = ^(NSString *strToken) {
                    if (![WShareUtil strNilOrEmpty:strToken]) {
                        [self requestListDataStrNum:pageNum isRefresh:isRefresh];
                    }else {

                        [WShareUtil showAlert:@"温馨提示" message:@"没有token"];

                        return ;

                        WLog(@"没有token");
                    }
                };

                WLog(@"%@====",[WShareUtil sharedData].strToken);
            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0005"]){

                [WShareUtil showAlert:@"温馨提示" message:@"您的服务已经到期"];
                return ;

            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0006"]){

                [WShareUtil showAlert:@"温馨提示" message:@"您被禁止登录"];
                return ;

            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0008"]){

                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的账号可能在其他设备登录,是否要重新登录？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新登录", nil];
                [alertView show];

                [WShareUtil sharedData].dicSession = nil;
                return ;
                WLog(@"没有用户");

            }

            if (isRefresh) {
                [self.arrMfG removeAllObjects];
            }

            for (NSDictionary *dic in returnDic[@"data"]) {
                FGModel *fGmodel = [FGModel mj_objectWithKeyValues:dic];
                [self.arrMfG addObject:fGmodel];
            }
            [WShareUtil removeModelDataWithFile:@"RegulationList"];
            [WShareUtil saveModelData:self.arrMfG WithFile:@"RegulationList"];
            [[self myTableView] reloadData];
            [self.myTableView.header endRefreshing];
            [self.myTableView.footer endRefreshing];

//            ///* --- 图片式提醒
//            UIView *view = [self.myTableView viewWithTag:10000];
//            [view removeFromSuperview];
//            HHNonePage *_nonePage = [[HHNonePage alloc]init];
//            _nonePage = nil;
//            if (_arrMfG.count == 0) {
//                _nonePage = [[HHNonePage alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//                _nonePage.tag = 10000;
//                [_myTableView addSubview:_nonePage];
//            }
//            //*/

            if ([returnDic[@"data"] count] < 10) {
                // 拿到当前的上拉刷新控件，变为没有更多数据的状态
                [self.myTableView.footer endRefreshingWithNoMoreData];
            }

        } failure:^(NSError *error) {
            [self noWifiRefershingEnd];
            WLog(@"请求失败");
        } showProgress:YES];
    }
}

#pragma mark - 下载文章详情数据
- (void)requestDataCid:(NSString *)cid {

    if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strToken]) {
        HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：tokesn过期后，获取一次就关掉）
        [loadToken loadToken];
        loadToken.tokenBlock = ^(NSString *strToken) {
            if (![WShareUtil strNilOrEmpty:strToken]) {
                [self requestDataCid:cid];
            }else {
                WLog(@"没有token");
            }
        };
        WLog(@"%@",[WShareUtil sharedData].strToken);
    }else {

        NSString *userId;
        if ([WShareUtil sharedData].dicSession) {
            userId = @"141978";
            if (userId == nil) {
                userId = @"";
            }

        }else {
            userId = @"";
        }
        NSString *uuid= @"e1e1e1";
        NSDictionary *parametersDict = @{@"jqbh":uuid,@"token":[WShareUtil sharedData].strToken,@"id":cid,@"userid":userId};
        // 字典转JSON字符串
        NSString *jsonData = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];

        // 加密JSON字符串
        WLog(@"加密JSON字符串的结果%@",[CommonFunc encryptWithText:jsonData]);//加密方法
        WLog(@"解密乱码后的结果%@",[CommonFunc decryptWithText:@"sZjh+Dfxf1kcn5u4bgq4g75bHbBQ6DlL2oF3ELtxXb8dkwb1w5GRyfm7huCriDvlsdsFDoOWLqzX7tt+NpCuiEApxy+2QONMEZpGLBejk+1ZPreDtd3O7Q=="]);//解密方法

        // 加密后字典参数
        NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:jsonData]};

        [WHttpTool POST:[WShareUtil getServerURL:ARTICLEINDEX] parameters:paramsDic success:^(id responseObject) {
            NSString *messageStr = [responseObject objectForKey:@"message"];
            NSString *successStr= [responseObject objectForKey:@"success"];
            // 解密请求回的数据（字典）
            [CommonFunc decryptWithText:messageStr];
            NSString *returnStr = [CommonFunc decryptWithText:messageStr];
            // json字符串转字典
            NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

            if ([returnDic[@"resultCode"] isEqualToString:@"EC0001"] || [returnDic[@"resultCode"] isEqualToString:@"EC0002"] ) {
                HHBaseLoadToken *loadToken = [[HHBaseLoadToken alloc] init];// 获取Token （目前先：token过期后，获取一次就关掉）
                [loadToken loadToken];
                loadToken.tokenBlock = ^(NSString *strToken) {
                    if (![WShareUtil strNilOrEmpty:strToken]) {
                        [self requestDataCid:cid];
                    }else {

                        [WShareUtil showAlert:@"温馨提示" message:@"没有token"];

                        return ;

                        WLog(@"没有token");
                    }
                };

                WLog(@"%@====",[WShareUtil sharedData].strToken);
            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0005"]){

                [WShareUtil showAlert:@"温馨提示" message:@"您的服务已经到期"];
                return ;

            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0006"]){

                [WShareUtil showAlert:@"温馨提示" message:@"您被禁止登录"];
                return ;

            }else if([returnDic[@"resultCode"] isEqualToString:@"EC0008"]){

                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的账号可能在其他设备登录,是否要重新登录？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重新登录", nil];
                [alertView show];

                [WShareUtil sharedData].dicSession = nil;
                return ;
                WLog(@"没有用户");

            }

            NSNumber *gid;
            if ([WShareUtil sharedData].dicSession) {
                gid = [WShareUtil getDataWithUserDefaultsForKey:GIDVALUE];
            } else {
                gid = [WShareUtil getDataWithUserDefaultsForKey:YKGIDVALUE];
            }
            NSNumber *rank = returnDic[@"rank"];

            WLog(@"%@gid",gid);
            WLog(@"%@rank",rank);

            if (gid.intValue == 1 && rank.intValue != 0) {
                [SVProgressHUD showImage:nil status:@"用户权限不够，去我的页面购买后才能查看"];
                [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
                [SVProgressHUD dismissWithDelay:1.];
                [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];
                return;
            }

            if (gid.intValue < rank.intValue) {
                [SVProgressHUD showImage:nil status:@"用户权限不够，去我的页面购买后才能查看"];
                [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
                [SVProgressHUD dismissWithDelay:1.];
                [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];
                return;
            }

//            TextDetailViewController *textDetailVC = [[TextDetailViewController alloc]init];
//            //跳转时隐藏标签栏
//            textDetailVC.hidesBottomBarWhenPushed=YES;
//            textDetailVC.dicData = returnDic;
//            [self.navigationController pushViewController:textDetailVC animated:YES];

        } failure:^(NSError *error) {
            WLog(@"请求失败");

        } showProgress:YES];

    }
}

//设置UITableViewCell的数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    RegulationCell *cell1;
    cell1  = [[self myTableView] dequeueReusableCellWithIdentifier: RegulationCellIndentifier];

    if (self.arrMfG.count > 0 && self.arrMfG != nil) {
        //[[self.arrMfG[indexPath.row]jdid] isKindOfClass:[NSString class]]

        if ([self.arrMfG[indexPath.row]jdid] == nil || [self.arrMfG[indexPath.row]jdid] == NULL){
            cell1.understandBtn.hidden = YES;

        }else {
            cell1.understandBtn.hidden = NO;
            cell1.delegate = self;
            cell1.understandBtn.tag = indexPath.row;
        }
        cell1.lbTitCell.text = [self.arrMfG[indexPath.row] strTitle];//标题
        cell1.lbTitCell.numberOfLines = 0;
        cell1.lbTitCell.textAlignment = NSTextAlignmentLeft;
        cell1.lbTitCell.textColor = [UIColor blackColor];
        cell1.lbTitCell.font = [UIFont systemFontOfSize:16];
        CGSize maximumLbTitle = CGSizeMake(WSCREENH_WIDTH - 26, MAXFLOAT);//labelsize的最大值
        CGSize expectSize = [cell1.lbTitCell sizeThatFits:maximumLbTitle];
        if (expectSize.height >= 20) {//38.33  19.33
            expectSize.height = 41.33;
        }

        cell1.cellTitH.constant = expectSize.height;
        cellTitH = expectSize.height;

        // ---------- 设置titleLB的行间距
        NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle  setLineSpacing:2];

        if ([WShareUtil strNilOrEmpty:cell1.lbTitCell.text]) {
            cell1.lbTitCell.text = @"";
        }
        NSMutableAttributedString  *setString = [[NSMutableAttributedString alloc] initWithString:cell1.lbTitCell.text];

        [setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [cell1.lbTitCell.text length])];
        [cell1.lbTitCell  setAttributedText:setString];// 设置Label要显示的text
        // ----------

        cell1.lbTimeCell.text = [self.arrMfG[indexPath.row] classtime];//时间
        cell1.lbNumCell.text = [self.arrMfG[indexPath.row] strInfo];//字号
    }
    //isKindOfClass:[NSString class]
    return cell1;

}

//行点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    [self requestDataCid:[self.arrMfG[indexPath.row] strId]];
}

//分组个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//列表行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.arrMfG count];
}

//设置行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return cellTitH + 68;
}


#pragma mark - DropDownMenu的几个方法
- (void)DOP {
    // 日期
    self.RQArrM = @[@"发文日期",@"近一个月",@"一到三年",@"三到五年",@"五年以前"];

    // 添加下拉菜单
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:44];
    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    _menu = menu;


}

//Column的个数（列）
- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 2;
}

//行数
- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (column == 0){
        return _FGFLArrM.count;
    }else {
        return _RQArrM.count;
    }
}

//标题
- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) { // 左按钮（分类）

        if (indexPath.row == 0 ) {
            return @"中央税收法规";
        }else{
            //return [_licenseList[indexPath.row] objectForKey:@"TEXT"];
            return self.FGFLArrM[indexPath.row];
        }

    } else {
        return self.RQArrM[indexPath.row];
    }
}

// new datasource
- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0 || indexPath.column == 1) {
        return [NSString stringWithFormat:@"ic_filter_category_%ld",(long)indexPath.row];
    }
    return nil;
}

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0 && indexPath.item >= 0) {
        return [NSString stringWithFormat:@"ic_filter_category_%ld",(long)indexPath.item];
    }
    return nil;
}

// 设置二级列表内容
- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    if (column == 0) {
        if (row == 0) {
            return self.FGSZArrM.count;
        }
    }
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        if (indexPath.row == 0) {
            return self.FGSZArrM[indexPath.item];
        }
    }
    return nil;
}
- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.item >= 0) {
        WLog(@"点击了 %ld - %ld - %ld 项目",indexPath.column,indexPath.row,indexPath.item);

        if (indexPath.column == 0) { // 二级列表（item>=0有item）（属于第一个column 所以column== 0 ）
            _cid = [_FGFLIDArrM objectAtIndex:indexPath.row];// 取法规分类的id
            _cid = [_FGSZIDArrM objectAtIndex:indexPath.item];// 取法规税种的id
            WLog(@"---%@",_cid);
            //            [self requestListDataStrNum:@"1" isRefresh:YES];
            [_myTableView.header beginRefreshing];
        }
    }else {
        WLog(@"点击了 %ld - %ld 项目",indexPath.column,indexPath.row);

        if (indexPath.column == 0) { // 一级列表(item<0无item)（属于第一个column 所以column== 0 ）
            _cid = [_FGFLIDArrM objectAtIndex:indexPath.row];// 取法规分类的id
            WLog(@"+++%@",_cid);
            //            [self requestListDataStrNum:@"1" isRefresh:YES];
            [_myTableView.header beginRefreshing];
        }
        else if (indexPath.column == 1) {
            _rq = [NSString stringWithFormat:@"%ld",indexPath.row];
            WLog(@"***%@",_rq);
            //            [self requestListDataStrNum:@"1" isRefresh:YES];
            [_myTableView.header beginRefreshing];
        }
    }
}

// 解读按钮实现的方法
- (void)jiedu:(UIButton *)button {

    if ([WShareUtil sharedData].dicSession) {
        [self requestDataCid:[self.arrMfG[button.tag] jdid]];
    }else {

        [SVProgressHUD showImage:nil status:@"请先登录"];
        [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
        [SVProgressHUD dismissWithDelay:1.];
        [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
        //        LoginViewController *loginVc = [[LoginViewController alloc]init];
        //        [self presentViewController:loginVc animated:YES completion:nil];
        //
        //        __weak LoginViewController *loginVcSelf = loginVc;
        //        loginVc.loginSesscion = ^{
        //
        //            [loginVcSelf dismissViewControllerAnimated:YES completion:nil];
        //            [self requestDataCid:[self.arrMfG[button.tag] jdid]];
        //        };
    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {

    }
}

-(void)dealloc{
    //移除所有通知监控
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

// 百度统计
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    NSString* cName = [NSString stringWithFormat:@"%@",  self.title, nil];
//    [[BaiduMobStat defaultStat] pageviewStartWithName:cName];
}

// 退出页面，建议在此处添加
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    NSString* cName = [NSString stringWithFormat:@"%@", self.title, nil];
//    [[BaiduMobStat defaultStat] pageviewEndWithName:cName];

}


@end
